package com.qf.Servlet;

import com.qf.entity.Book;
import com.qf.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author Wy
 * @version V1.0
 * @Project day41-3
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/15 13:14
 */
@WebServlet(name = "uupdatebookServlet",urlPatterns = "/updatebook")
public class updatebookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        String bookIds = request.getParameter("book");
        String bookName = request.getParameter("bookName");
        String author = request.getParameter("author");
        Double price = Double.parseDouble(request.getParameter("price"));
        String description = request.getParameter("description");
        String publisher = request.getParameter("publisher");

        Book book = new Book(null,bookName, price, description, author, publisher);
        System.out.println(book);
        BookServiceImpl bookService = new BookServiceImpl();
        int updatebooks = bookService.updatebooks(book, bookIds);
           if(updatebooks>=1){
               response.sendRedirect(request.getContextPath()+"/bookList");
                 return;
           }else{
               session.setAttribute("msg","添加失败");
               response.sendRedirect(request.getContextPath()+"/uppdateBook.jsp");
               return;

           }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                  doPost(request,response);
    }
}
